package com.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.service.*;
import com.example.shiro.AccountProfile;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseController {
    @Autowired
    HttpServletRequest req;

    @Autowired
    IMPostService postService;


    @Autowired
    IMUserMessageService messageService;

    @Autowired
    IMCommentService commentService;

    @Autowired
    IMUserService userService;

    @Autowired
    IMCategoryService categoryService;

    public Page getPage(){
        int pn = ServletRequestUtils.getIntParameter(req, "pn", 1);
        int size = ServletRequestUtils.getIntParameter(req, "size", 2);

        // 1分页信息 2分类 3用户 4置顶 5精选 6排序
       return new Page(pn,size);
    }

    protected AccountProfile getProfile(){
        return (AccountProfile) SecurityUtils.getSubject().getPrincipal();
    }

    protected Long getProfileId(){
        return getProfile().getId();
    }
}
